//
//  WHUpdateVersionView.m
//  WHPersonalData
//
//  Created by mac on 2018/5/29.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "WHUpdateVersionView.h"
#import "SDAutoLayout.h"

@interface WHUpdateVersionView ()

@property(nonatomic,weak)UIImageView*backgroudImage;

@property(nonatomic,weak)UIButton*deleteButton;

@property(nonatomic,weak)UIButton*updateButton;

@end

@implementation WHUpdateVersionView


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        
        [self setUpAllChilds];
        
       
        
    }
    return self;
}

-(void)setUpAllChilds
{
    
    /**   图片   **/
    UIImageView*backgroudImage =[[UIImageView alloc]init];
    [self  addSubview:backgroudImage];
    backgroudImage.image =[UIImage imageNamed:@"updateBackground"];
    _backgroudImage = backgroudImage;
    
    /**  删除按键  **/
    UIButton*deleteButton = [[UIButton alloc]init];
    [deleteButton setImage:[UIImage imageNamed:@"updateDelete"] forState:UIControlStateNormal];
    
    deleteButton.titleLabel.font =[UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];
    deleteButton.tag = 200;
    [deleteButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:deleteButton];
    _deleteButton = deleteButton;

    
    /**  立即更新  */
    UIButton*updateButton = [[UIButton alloc]init];
    [updateButton setTitle:@"立即更新" forState:UIControlStateNormal];
    //[updateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [updateButton setTitleColor:RGBColor(61,178,239) forState:UIControlStateNormal];
    updateButton.titleLabel.font =[UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];

    updateButton.tag = 201;
    [updateButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:updateButton];
    _updateButton = updateButton;
   

   [self setUpChildLayout];
    
}

-(void)setUpChildLayout
{
    _backgroudImage.sd_layout
    .leftSpaceToView(self,kMarginH*2)
    .topSpaceToView(self,kMarginH*2)
    .rightSpaceToView(self,kMarginH*2)
    .heightIs(ScreenH/3);
    

    _deleteButton.sd_layout
    .rightSpaceToView(self,kMarginH*3)
    .topSpaceToView(self,kMarginH*3)
    .widthIs(kMarginH*2)
    .heightIs(kMarginH*2);
    
    
    _updateButton.sd_layout
    .leftSpaceToView(self,kMarginH*5)
    .topSpaceToView(self.backgroudImage,kMarginH*5)
    .rightSpaceToView(self,kMarginH*5)
    .heightIs(ScreenH/12);
    
    _updateButton.layer.cornerRadius =ScreenH/24;
    _updateButton.layer.borderWidth = 1;
    _updateButton.layer.borderColor =RGBColor(61,178,239).CGColor;
    
}


-(void)buttonClick:(UIButton*)button
{
    
    
    if (_delegate &&[_delegate respondsToSelector:@selector(updateVersionViewButtonClick:)]) {
        [_delegate updateVersionViewButtonClick:button];
    }
    
    
    
    
    
    
}

@end
